package com.coffeeloversupportlibrary.core.data.http;

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * @author puyv
 * @createTime 2021/11/3 16:59
 * @projectName CoffeeLoverSupportLibrary
 * @className RetrofitProvider.java
 * @description TODO
 */
public class RetrofitProvider {
      //http://10.7.88.9:8001/article/articleList
      private static final String BASE_URL="http://turing.gz2vip.91tunnel.com/";
      private static final String BASE_URL_TWO="http://v.juhe.cn/";
      private volatile static RetrofitProvider INSTANCE = null;
      private Retrofit retrofit;

      /**
      * @date 2021/11/3 20:42
      * @params []
      * @return
      * @description 添加自定义拦截器，以解决多域名问题
      */
      private RetrofitProvider() {
            OkHttpClient client=new OkHttpClient.Builder().
                    build();

            retrofit=new Retrofit.Builder().
                    addConverterFactory(GsonConverterFactory.create()).
                    baseUrl(BASE_URL).
                    client(client).
                    build();
      }

      /**
      * @date 2021/11/3 20:25
      * @params []
      * @return com.coffeeloversupportlibrary.core.data.retrofit.RetrofitProvider
      * @description 线程安全获取 RetrofitProvider 单例
      */
      public static RetrofitProvider getInstance() {
            if (INSTANCE==null) {
                  synchronized (RetrofitProvider.class) {
                        if (INSTANCE==null) {
                              INSTANCE=new RetrofitProvider();
                        }
                  }
            }
            return INSTANCE;
      }

      /**
      * @date 2021/11/3 20:28
      * @params []
      * @return retrofit2.Retrofit
      * @description 获取 Retrofit 对象
      */
      public Retrofit getRetrofit(){
            return this.retrofit;
      }
}
